package com.kadron.size;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;

import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;

import com.kadron.common.KConst;
import com.kadron.dao.KSizeDAO;
import com.kadron.entity.Size;
import com.kadron.manager.KMessageManager;
import com.kadron.manager.KSelection;

@AutoCreate
@Scope(ScopeType.PAGE)
@Name("kSizeListManager")
public class KSizeListManager extends KMessageManager implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3111988099407754250L;
	
	private List<Size> sizeList = new LinkedList<Size>();
	
	@In
	private KSizeDAO sizeDAO;
	
	@Create
	public void init() {
		sizeList = sizeDAO.getAll(Size.class);
	}

	public List<Size> getSizeList() {
		return sizeList;
	}
	
	public String edit(Long id) {
		if (id == null) {
			bad(KConst.BAD_THING);
			return null;
		}
		KSelection kselection = (KSelection) Component.getInstance("kSelection");
		kselection.setItemId(id);
		return "e_size";
	}
	
	public void delete(Size size) {
		if (size == null) {
			bad(KConst.BAD_THING);
			return;
		}
		sizeList.remove(size);
		sizeDAO.delete(size);
	}
}
